import xlrd
import os
from Base import GetYamlFile

class Read_Excel:

    def __init__(self,fileName):
        self.fileName=fileName
        global  workbook
        workbook=xlrd.open_workbook(fileName)


    def get_SheetName(self):
        sheet=workbook._sheet_names
        return sheet

    def read_Excel(self,name,row,col):
        sheet=workbook.sheet_by_name(name)
        return sheet.row(row)[col].value

    def get_ColNum(self,name):
        sheet=workbook.sheet_by_name(name)
        num=sheet.nrows
        return num
    def get_RowNums(self,name):
        sheet=workbook.sheet_by_name(name)
        num=sheet.nrows
        return num

    def get_case(self,name):
        cases=[]
        sheet=workbook.sheet_by_name(name)
        # print(sheet.nrows)
        for i in range(1,sheet.nrows):
            row_data =sheet.row_values(i)
            # print(row_data)
            cases.append(row_data)
        # print(cases)
        return cases
if __name__=='__main__':
    YmlList=GetYamlFile.getYamlFile()
    TestCasePath=YmlList["simulatorPath"]
    PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))
    REPORT_XLSX_DIR = os.path.join(PROJECT_ROOT, TestCasePath)
    readBook=Read_Excel(REPORT_XLSX_DIR)
    print(readBook.get_case("1"))
    testData =readBook.get_case("1")
    for itemData in testData:
        print(itemData[1][0:2])
        print(itemData[1][2:])
    for sheetName in readBook.get_SheetName():
        print(sheetName)